/**
 * 
 */
package org.t2.game.server.module.player.service;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.gaming.ruler.lifecycle.Lifecycle;
import org.gaming.service.service.AbstractService;
import org.springframework.stereotype.Service;
import org.t2.game.server.module.player.model.PlayerSwitch;

/**
 * 
 */
@Service
public class PlayerSwitchService extends AbstractService<PlayerSwitch> implements Lifecycle {

	private ConcurrentMap<Long, PlayerSwitch> oriSwitchMap = new ConcurrentHashMap<>();
	private ConcurrentMap<Long, PlayerSwitch> destSwitchMap = new ConcurrentHashMap<>();
	
	@Override
	public void mergeServer(int mergeDbZoneId) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void start() throws Exception {
		List<PlayerSwitch> list = this.repository().getAll();
		for(PlayerSwitch player : list) {
			oriSwitchMap.put(player.getOriPlayerId(), player);
			destSwitchMap.put(player.getDestPlayerId(), player);
		}
	}
	
	public PlayerSwitch getOriSwitch(long playerId) {
		return oriSwitchMap.get(playerId);
	}
	
	public PlayerSwitch getDestSwitch(long playerId) {
		return destSwitchMap.get(playerId);
	}
	
	public void delete(PlayerSwitch playerSwitch) {
		oriSwitchMap.remove(playerSwitch.getOriPlayerId());
		destSwitchMap.remove(playerSwitch.getDestPlayerId());
		this.repository().delete(playerSwitch);
	}
	
	@Override
	public void insert(PlayerSwitch t) {
		super.insert(t);
		oriSwitchMap.put(t.getOriPlayerId(), t);
		destSwitchMap.put(t.getDestPlayerId(), t);
	}
	
}
